-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ui-core]: add onSuccess and onError callback for useLoadData hook #3849
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I reiterated my point on the "I" convention, please have a look. We can discuss if you want.
@@ -61,8 +66,16 @@ const useLoadData = <T, U = unknown>(url?: string, options?: IOptions<T, U>): IU | |||
const fetchUrl = localOptions?.urlPrefix ? `${localOptions.urlPrefix}${url}` : url; | |||
const response = await get<T, U>(fetchUrl, localOptions?.params, fetchOptions); | |||
setData(response); | |||
setError(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setError not required as it is set above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is required in the edge case.
- First call made which resulted in error. Hence error is set to non-null and data is unchanged.
- Second call is made either by triggering
refetch
function or by changing and of theoptions
. When its a success, the old error state is still set to non-null and data after second call is also set to non-null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I over-sighted the setError at line 63.
Thanks for flagging. I have removed it
} catch (error) { | ||
setError(error instanceof Error ? error : new Error(error)); | ||
setData(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old data will be removed do we want that?
lets say there is table already loaded and we are calling useLoadData hook in a interval. in case of api fails, we can throw error but should we remove the tables data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this makes sense.
What changes were proposed in this pull request?
How was this patch tested?
Please review Hue Contributing Guide before opening a pull request.